package org.example.executor.testCpu;

import java.util.Date;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author liyishan
 * @date 2024/8/5 13:34
 * @apiNote
 */

public class CustomThreadFactory implements ThreadFactory {
    private final AtomicInteger threadNumber = new AtomicInteger(1);
    private final String prefix;

    CustomThreadFactory(String prefix) {
        this.prefix = prefix;
    }

    @Override
    public Thread newThread(Runnable r) {
        String threadName = prefix + threadNumber.getAndIncrement();
        Thread thread = new Thread(r, threadName);
        return thread;
    }

}
